/**
 * @Author：ming
 * @Date：2023/9/26 7:02 PM
 * @Filename：Lc169
 */

import java.util.HashMap;

/**
 * @author ming
 */
public class Lc169 {
    public int majorityElement(int[] nums) {
        int len = nums.length;
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < len; i++) {
            if (map.containsKey(nums[i])) {
                map.put(nums[i], map.get(nums[i]) + 1);
            } else {
                map.put(nums[i], 1);
            }
        }

        int num = -1;

        for (Integer c : map.keySet()) {
            if(map.get(c)>=(int)(len+0.5)/2){
                num =c;
            }
        }

        return num;
    }
}
